<?php 
	include_once('Configs/paging.php');
	//include_once('Models/HocKiNamHoc.php');
	include_once('Models/Quyen.php');
    include_once('Models/ChucNang.php');
?>
<script type="text/javascript" src="Libraries/js/js.js"></script>

<script language="javascript">

function getValue(id){
    
    for (var i=0; i<document.phanquyen.cbochucnang.length; i++){
       if ( document.phanquyen.cbochucnang[i].value == document.getElementById("macn" + id).innerHTML){
            document.phanquyen.cbochucnang.selectedIndex = i;    
       }
    }
    
   
    document.phanquyen.btnthem.disabled=true;
	
	
}
function confirmDelete(){
    if (confirm("Bạn có chắc muốn xóa quyền thực hiện chức năng này không?")){
        return true;
    }
    return false;
    
}
function empty(){
	
	document.phanquyen.btnthem.disabled=false;
    document.phanquyen.btnxoa.disabled=true;
	document.phanquyen.cbochucnang.selectedIndex = 0;
	//document.phanquyen.chkchon.checked = false;
	for (var i=0; i<document.phanquyen.chkchon.length; i++){
       if ( document.phanquyen.chkchon[i].checked == true){
            document.phanquyen.chkchon[i].checked = false;
			break;   
       }
    }
}


</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="Libraries/css/jquery.datepick.css" rel="stylesheet" type="text/css"></head>
<title>Untitled Document</title>
</head>

<body>
<form name="phanquyen" method="POST">
<table align="center" class="font" width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Phân Quyền</td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top"><table border="0" align="center">
      <tr>
        <td colspan="2">&nbsp;</td>
        </tr>
      <tr>
        <td align="right">Quyền</td>
        <td><select name="cboquyen"  onchange="hienThiDSChucNang(this.value);">
          <option value=" "></option>
          <?php
                    $quyen = new Quyen();
                    $result = $quyen->dsQuyen();
                    while ($rows = mysql_fetch_array($result)){
                        echo "<option value='".$rows['maquyen']."'>".$rows['diengiai']."</option>";
                    }
                    if (isset($_POST['cboquyen'])) echo "<script language=\"javascript\">for(var i=0;i<document.phanquyen.cboquyen.length;i++){if(document.phanquyen.cboquyen[i].value=='$maquyen'){document.phanquyen.cboquyen.selectedIndex=i;break;}}</script>";
                ?>
        </select></td>
      </tr>
      <tr>
        <td align="right">Chức năng</td>
        <td><select name="cbochucnang">
          <option value="0"></option>
          <?php
                    $cn = new ChucNang();
                    $result = $cn->dsChucNang();
                    while ($rows = mysql_fetch_array($result)){
                        echo "<option value='".$rows['macn']."'>".$rows['tencn']."</option>";
                    }
                ?>
        </select></td>
      </tr>
      <tr>
        <td colspan="2" align="center">
			<input name="btntaomoi" type="button" class="button_1" id="btntaomoi" value="Tạo mới" onClick="return empty();"/>
			<input type="submit" name="btnthem" value="Thêm" class="button_1"/>&nbsp;&nbsp;
			<input type="submit" name="btnxoa" value="Xóa" class="button_1" onClick="return confirmDelete();"/>		</td>
        </tr>
    </table></td>
  </tr>
</table>
<br/>
<br/>
<div id="danhsachcn">
 <?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{
    
   
	$quyen = new Quyen();
    $quyen->setMaQuyen($maquyen);
	$result = $quyen->dsChucNangQuenThucHien();
        echo "<table align='center' class='font' width='500' border='0' cellspacing='0' cellpadding='0'>";
          echo "<tr>";
            echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
            echo "<td align='center' class='main_1'>Danh sách Khoa</td>";
            echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
          echo "</tr>";
          echo "<tr >";
            echo "<td class='border_1' colspan='3' valign='top'><table width='500' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
              echo "<tr>";
                echo "<td width='30' align='center' class='main_3'>STT</td>";
                echo "<td width='50' align='center' class='main_3'>Mã CN</td>";
                echo "<td width='300' align='center' class='main_3'>Tên Chức năng </td>";
               
        		echo "<td width='50' align='center' class='main_3'>Chọn</td>";
                
                echo "</tr>";
             
          
        	
        	 	
        		
        		
        		$bg=($curPg-1)*10+1;
        		$end=$bg+9;	
        		$num=mysql_num_rows($result);
        		$i=0;
        		$ci=0;
        		
        		while($row=mysql_fetch_array($result))
        		{
  		            /*$cn = new ChucNang();
                    $parent = $row['parent'];
                    $resultcn = $cn->thongTinCN($parent);
                    $rowcn = mysql_fetch_array($resultcn);
                    if ($row['parent']==''){
                        $tenncn = $row['tencn'];
                    }
                    else $tenncn = $rowcn['tencn'];*/
        			$i++;
        			$ci=2-$i%2;
        			
        			echo "<tr>";
        			echo "<td align='center' class='main_3'>".$i."</td>";
                    echo "<td class='level_1_$ci' align='center'><div id='macn$i'>".$row['macn']."</div></td>";
        			echo "<td class='level_1_$ci' align='left'><div id='tencn$i'>".$row['tencn']."</div></td>";
        		
        			
        		
        			echo "<td class='level_1_$ci' align='center'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
        		
        			echo "</tr>";
        		
        			
        		}
        		
        	
        
        
              
            echo "</table></td>";
          echo "</tr>";
        echo "</table>";
    //}
}
?>
</div>
</form>
</body>
</html>
